﻿using UnityEngine;
using System.Collections;
using ShooterGameMOD_Besiege.Player;

namespace ShooterGameMOD_Besiege.Player
{
    /// <summary>
    /// 玩家碰撞脚本
    /// </summary>
    public class PlayerCollisionScript : MonoBehaviour
    {

        SphereCollider sc;
        PlayerWeaponScript playerWeapon;

        // Use this for initialization
        void Start()
        {
            playerWeapon = PlayerScript.player.GetComponent<PlayerWeaponScript>();
            sc = GetComponent<SphereCollider>();
            sc.isTrigger = true;
            
                     
        }
         
        // Update is called once per frame
        void Update()
        {
            if (PlayerScript.playerCreated)
            {

            }
        }

        private void OnTriggerEnter(Collider other)
        {

            if (StatMaster.levelSimulating)

            {
                Debug.Log(other.name + " collisionScript " + other.transform.parent.name);

                //if (other.transform.parent.name == WeaponScript.WeaponsList.Crossbow.ToString() && PlayerScript.player.GetComponent<PlayerControllerScript>().Weapon == null)
                //{
                //    Debug.Log("weapon");
                //    other.transform.parent.gameObject.AddComponent<Weapons.CrossBowScript>();

                //}
                if (playerWeapon.firstWeapon == null)
                {
                    if (other.transform.parent.name == WeaponScript.WeaponsList.Crossbow.ToString())
                    {
                        GameObject go = other.transform.parent.gameObject;
                        if (playerWeapon.weaponIndicator == -1 || playerWeapon.currentWeaponKind == WeaponScript.WeaponKind.None)
                        {
                            playerWeapon.weaponIndicator = 0;
                            playerWeapon.currentWeapon = go;
                            playerWeapon.currentWeaponKind = WeaponScript.WeaponKind.FirstWeapon;
                        }
                        playerWeapon.firstWeapon = go;
                        go.AddComponent<Weapon.CrossBowScript>();

                    }
                }
                if (playerWeapon.secondWeapon == null)
                {

                }
                if (playerWeapon.thirdWeapon == null)
                {

                }
                if (playerWeapon.fourthWeapon == null)
                {
                    if (other.transform.parent.name == WeaponScript.WeaponsList.Bomb.ToString())
                    {
                        GameObject go = other.transform.parent.gameObject;
                        if (playerWeapon.weaponIndicator == -1 || playerWeapon.currentWeaponKind == WeaponScript.WeaponKind.None)
                        {
                            playerWeapon.weaponIndicator = 3;
                            playerWeapon.currentWeapon = go;
                            playerWeapon.currentWeaponKind = WeaponScript.WeaponKind.FourthWeapon;
                        }
                        playerWeapon.fourthWeapon = go;
                        go.AddComponent<Weapon.BombScript>();

 
                    }
                }

            }

            
        }
    }
}
